'use strict';

var moment = require('moment');

module.exports = app => {
  const {
    INTEGER,
    STRING,
    DATE
  } = app.Sequelize;

  const Message = app.model.define('messages', {
    mid: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    content: STRING,
    ruid: INTEGER, // 回复人uid
    puid: INTEGER, // 发送人uid
    state: INTEGER, 
    isRead: {
      type: INTEGER,
      defaultValue: 0
    },  // 是否已读 1已读 0未读
    tid: INTEGER, // 对应帖子id
    cid: INTEGER, // 对应的评论id
    rcid: INTEGER, // 对应的评论回复id
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format('YYYY-MM-DD HH:mm:ss');
      }
    },
  });

  Message.associate = function() {
    
  };

  return Message;
};